
export default {
  getFile (base64Text) {
    function b64toBlob (b64Data, contentType, sliceSize) {
      contentType = contentType || ''
      sliceSize = sliceSize || 512
      let byteCharacters = atob(b64Data)
      let byteArrays = []
      for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
        let slice = byteCharacters.slice(offset, offset + sliceSize)
        let byteNumbers = new Array(slice.length)
        for (let i = 0; i < slice.length; i++) {
          byteNumbers[i] = slice.charCodeAt(i)
        }
        let byteArray = new Uint8Array(byteNumbers)
        byteArrays.push(byteArray)
      }
      return new Blob(byteArrays, { type: contentType })
    }
    function getContentType (base64) {
      return /data:([^;]*);/i.exec(base64)[1]
    }

    function getData (base64) {
      return base64.substr(base64.indexOf('base64,') + 7, base64.length)
    }
    function getBlob (base64) {
      return b64toBlob(getData(base64), getContentType(base64))
    }
    let downLoad = document.createElement('a')
    downLoad.setAttribute('id', 'downloadFile')
    let blob = getBlob(base64Text)
    // var FileSaver = require('file-saver')
    // FileSaver.saveAs(blob, 'myFile.pdf')
    // downLoad.setAttribute('href', URL.createObjectURL(blob))
    // console.log(URL.createObjectURL(blob))
    // window.location.href = URL.createObjectURL(blob)
    // downLoad.setAttribute('download', 'myfile.pdf')
    // downLoad.setAttribute('target', '_blank')
    // downLoad.style.display = 'none'
    // document.body.appendChild(downLoad)
    // downLoad.click()
    window.open(URL.createObjectURL(blob), '_blank')
  }
}
